# Contributor: Hidde van der Heide <hvanderheide@nexuz.net>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=opendmarc
pkgver=1.4.2
pkgrel=0
pkgdesc="A free open source implementation of the DMARC specification"
url="https://github.com/trusteddomainproject/OpenDMARC"
arch="all"
license="BSD-3-Clause Sendmail"
makedepends="libmilter-dev libspf2-dev autoconf automake libtool"
pkgusers="$pkgname"
install="$pkgname.pre-install"
subpackages="$pkgname-doc $pkgname-dev $pkgname-libs $pkgname-openrc"
source="$pkgname-$pkgver.tar.gz::https://github.com/trusteddomainproject/OpenDMARC/archive/rel-$pkgname-${pkgver//./-}.tar.gz
	dmarcfail-fix-shebang.patch
	fix-importstats-ignores-HistoryFile-path.patch
	config-defaults.patch
	$pkgname.initd
	$pkgname.confd
	"
builddir="$srcdir/OpenDMARC-rel-$pkgname-${pkgver//./-}"

# secfixes:
#   1.4.1.1-r3:
#     - CVE-2021-34555

prepare() {
	default_prepare
	autoreconf -vi
}

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--localstatedir=/var \
		--with-installdir=/usr \
		--with-spf \
		--with-spf2-lib=/usr/lib \
		--with-spf2-include=/usr/include/spf2
	make
}

check() {
	opendmarc/opendmarc -V

	make check
}

package() {
	make DESTDIR="$pkgdir" install

	cd "$pkgdir"

	install -m 644 -D "$builddir"/opendmarc/opendmarc.conf.sample \
		./etc/$pkgname/opendmarc.conf
	install -m 755 -D "$srcdir"/$pkgname.initd ./etc/init.d/$pkgname
	install -m 644 -D "$srcdir"/$pkgname.confd ./etc/conf.d/$pkgname
	install -m 750 -o $pkgusers -g mail -d ./var/spool/$pkgname

	# Not needed, standard SPDX licenses.
	rm -Rf ./usr/share/doc/$pkgname/LICENSE*
}

sha512sums="
415278c6c09460379538ad10ea4033815a677ddad138b8a07609c287360d1739acdba5d1fe07d0e35764850af8a141c0c70a9311254104b93d2c1bbc8b6f7a69  opendmarc-1.4.2.tar.gz
a8585104490d42ecb2acce40df2e36fc5ed6155fecb16a9de5606703b1b3f5fc7f84f2933350fa3ff8f7da133bc251f30dc33b9c1310bc64e801179de68df026  dmarcfail-fix-shebang.patch
0c663a3f1341707bf2e83e6d418b2696b461afdc64cfe94d5bb6013d2832d48e8347524a942d2c56743e3fd0075f2d0481df032de38b220dfacefb16349b6a3f  fix-importstats-ignores-HistoryFile-path.patch
6854cbd0357f444f596658bf55ba00534ffb87aebe872ac7ae4329c8e0132be1c12bed528741ecb3561621fc3b9c747eb094e0a90f53efe70f78aa4d2e515e16  config-defaults.patch
d3ddde80f609c6d4d7be547d7285bab3775284c05102b36a243a7389461e6304a0e1658a46ec0785195daa3ce89a939eab05203cd35e3a080fd04ccbfdd9e07a  opendmarc.initd
325a16efdd66e49fc15583d9ced38d70032601707fb82569e5967745a11d1fa216e720b3122929614ab0a322468a22a0bdd9cab9110fe24da231ef5a337177df  opendmarc.confd
"
